#coding:utf-8

import json

from es_store import initEsDocumentStore


def get_doc(i):
    es = initEsDocumentStore()
    r = es.get(i)
    return r

def get_title(ns):
    es = initEsDocumentStore()
    for i in ns:
        r = es.get(i)
        print i,r['title']

def get_doc_title(location1,location2):
    es = initEsDocumentStore()
    f1 = open(location1,mode='r')
    f2 = open(location2,mode='w')

    for line in f1:
        i1,i2,z = line.strip().split(',')
        t1 = es.getTitle(i1)
        t2 = es.getTitle(i2)
        #line = json.dumps((i1,t1,i2,t2),ensure_ascii=False)
        line = "%s,%s,%s,%s,%s"%(i1,t1,i2,t2,z)
        f2.write(line.encode('utf-8')+'\n')


    f1.close()
    f2.close()

if __name__ == '__main__':

    print 'Hi'

    #i = "4783271402"
    #r = get_doc(i)
    #print r['title']

    #ns = ['4675919504','4675227659','4675458501','4675401983']
    #ns = ['4517164945','4516582363']
    #get_title(ns)

    location1 = 'data/issue.u.txt'
    location2 = 'data/issue.title.txt'

    get_doc_title(location1,location2)

